{extend name="./app/admin/view/main.html" /}
{block name="title"}
{assign name="itemName" value="账户" /}
{$itemName}管理 - {/block}
{block name="style"}
<style>
</style>
{/block}
{block name="main"}

<header class="nicemip-container-header">
    <div class="float-left">
        <h4>{$itemName}管理</h4>
    </div>
</header>
<main class="nicemip-container-body" style="height: calc(100% - 50px)">
<div class="row">
    <div class="col-md-6">
    <section class="nice-box">
        <section class="nice-box-body">
            <i-form ref="form" :model="form" :label-width="100" :rules="rules">
                <Form-item label="原密码" prop="oldPassword">
                    <i-Input  type="password" v-model="form.oldPassword" placeholder="原密码"></i-Input>
                </Form-item>
                <Form-item label="新密码" prop="newPassword">
                    <i-Input v-model="form.newPassword" type="password" placeholder="新密码"></i-Input>
                </Form-item>
                <Form-item label="确认密码" prop="rpassword">
                    <i-Input v-model="form.rpassword" type="password" placeholder="确认密码"></i-Input>
                </Form-item>
                <Form-item >
                    <i-Button type="primary" @click='passwordSave("form")'>保存</i-Button>
                </Form-item>
                
            </i-form>
        </section>
    </section>
    </div>
</div>
</main>
{/block}
    
{block name="javascript"}
{__block__}

<script src="https://cdn.bootcss.com/blueimp-md5/2.7.0/js/md5.min.js" type="text/javascript" charset="utf-8"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            itemName: '{$itemName}',
            form: {
                oldPassword: '',
                newPassword: '',
                rpassword: '',
            },
            rules: {
                oldPassword: [{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur'
                    },
                ],
                newPassword: [{
                        required: true,
                        message: '请输入新密码',
                        trigger: 'blur'
                    },
                ],
                rpassword: [{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur'
                    },
                ],

            },
        },
        watch: {
             
        },
        mounted() {
        },
        methods: {
            passwordSave(formName) {
                this.$refs[formName].validate((valid) => {
                    if(valid) {
                        let _this = this;
                        this.$nicemip.ajax('{$domain}/user/ApiUserUser/userPasswordEdit', {
                            oldPassword: md5(_this.form.oldPassword),
                            newPassword: md5(_this.form.newPassword),
                            rpassword: md5(_this.form.rpassword),
                        }).then(function(res) {
                            if(res.code == 1) {
                                _this.$Message.success('修改成功');
                                location.href = '{$domain}/{$Think.config.admin}/login';
                            }
                        });
                    } else {
                        return false;
                    }
                });
            }
        }
    })
  </script>
{/block}